package com.cn.delan.web.mvc.admin.action;

import java.io.File;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.cn.delan.core.util.FileUtil;
import com.cn.delan.web.mvc.admin.AdminConst;
import com.cn.delan.web.mvc.core.action.AbstractAction;
/**
 * 文件重命名
 * @author BingGo
 *
 */
public class ChangeFileNameAction extends AbstractAction {

	@Override
	public ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String path = this.getParameter(AdminConst.REQUEST_PARA_PATH);
		String newName = this.getParameter(AdminConst.REQUEST_PARA_NEWNAME);
		File file = new File(path);
		File newFile = new File(file.getParentFile(),newName);
		PrintWriter writer = this.getWriter();
		if(file.renameTo(newFile)){
			//改名成功
			writer.write(this.getMessage(AdminConst.MESSAGE_CHANGENAME_SUCCESS));
		}else{
			//改名失败
			writer.write(this.getMessage(AdminConst.MESSAGE_CHANGENAME_FAIL));
		}
		return null;
	}

}
